﻿using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Caching.Memory;
using RTW.Core.Extensions;
using RTW.Models;
using RTW.Servers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace RTW.Web.Component
{
    public class DpetTreeList : ViewComponent
    {
        DepartmentServer _departmentServer;
        private IMemoryCache _memoryCache;
        private string cacheKey = "DepartmentTree";


        public DpetTreeList(IMemoryCache memoryCache)
        {
            _departmentServer = new DepartmentServer();
            _memoryCache = memoryCache;
        }

        public async Task<IViewComponentResult> InvokeAsync()
        {
            var items = new List<TDepartment>();
            //if (!_memoryCache.TryGetValue(cacheKey, out items))
            //{
            //    items = await _departmentServer.GetDpetTreeList();
            //}
            //if (items?.Count==0)
            //{
                items = await _departmentServer.GetDpetTreeList();
            //}
            //_memoryCache.Set(cacheKey, items, TimeSpan.FromMinutes(10));
            return View(items);
        }


    }




}
